import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;

public class ListPractice1 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();

        System.out.println("请录入学生信息");
        while(true) {
            System.out.println("1：继续录入，0：结束录入");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            if (choice == 0) {
                scanner.close();
                break;
            }
            System.out.println("请输入学生姓名");
            String name = scanner.next();
            System.out.println("请输入学生年龄");
            int age = scanner.nextInt();

            Student st = new Student(name, age);
            list.add(st);
            System.out.println("录入成功");
        }
        for(Object st: list) {
            System.out.println(st);
        }
    }
}

class Student {
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student student)) return false;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
